package com.uui.action.menu;

import java.util.HashMap;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.uui.bean.FirstMenu;
import com.uui.service.menu.MenuService;
import com.uui.util.ResultMap;

@Controller
public class MenuController {
	@Autowired
	MenuService menuService;
	Logger logger = Logger.getLogger(MenuController.class);

	@RequestMapping("queryMainMenu")
	@ResponseBody
	public List<ResultMap<String, Object>> queryProduct(HttpServletRequest request) {
		HashMap<String, Object> whereMap = new HashMap<String, Object>();
		List<ResultMap<String, Object>> product = menuService.queryMainMenu(whereMap);
		return product;
	}
	
	@RequestMapping("updateMainMenu")
	@ResponseBody
	public List<ResultMap<String, Object>> updateProduct(HttpServletRequest request,FirstMenu menu) {
		logger.info(menu);
		menuService.updateMainMenu(menu);
		return null;
	}
	
	@RequestMapping("addMainMenu")
	@ResponseBody
	public List<ResultMap<String, Object>> addMainMenu(HttpServletRequest request,FirstMenu menu) {
		logger.info(menu+"==============================");
		System.out.println(menu + "-------------------------------------");
		menuService.addMainMenu(menu);
		return null;
	}
	
	@RequestMapping("deleteMainMenu")
	@ResponseBody
	public List<ResultMap<String, Object>> deleteProduct(HttpServletRequest request,String id) {
		menuService.deleteMainMenu(id);
		return null;
	}

	@RequestMapping("queryMenu")
	@ResponseBody
	public List<ResultMap<String, Object>> queryMenuById(HttpServletRequest request, String product_no) {
		HashMap<String, Object> whereMap = new HashMap<String, Object>();
		whereMap.put("menu_id", product_no);
		List<ResultMap<String, Object>> menu = menuService.queryMenu(whereMap);
		return menu;
	}

	@RequestMapping("menuManager")
	public String menuManager(HttpServletRequest request, HttpServletResponse response) {
		return "menu";
	}
	
	@RequestMapping("test")
	public String test(HttpServletRequest request, HttpServletResponse response) {
		return "test";
	}
	
	@RequestMapping(value="/queryauthority",method=RequestMethod.GET)
	public List<ResultMap<String, Object>> queryAuthority() throws Exception{
		return menuService.queryAuthority();
	}
}